package com.suning.sawp.service.impl.oga;

import java.util.List;
import java.util.Map;

import org.joda.time.LocalDate;
import org.springframework.stereotype.Service;

import com.google.common.collect.Maps;
import com.suning.sawp.dto.oga.bi.SimpleRange;
import com.suning.sawp.po.bi.BiDevelopInfo;
import com.suning.sawp.po.bi.BiStaffDevelop;
import com.suning.sawp.po.bi.BiStaffDevelopDayEntity;
import com.suning.sawp.po.bi.BiStoreDevelop;
import com.suning.sawp.po.bi.BiStoreDevelopDayEntity;
import com.suning.sawp.service.impl.oga.bi.BIDevelopStatsService;
import com.suning.sawp.service.impl.oga.bi.support.Callback;
import com.suning.sawp.service.impl.oga.bi.support.SimpleRanges;

@Service("biDevelopStatsServiceDay")
public class BIDevelopStatsServiceDay extends BIDevelopStatsService {
    @Override
    protected BiStoreDevelop queryStoreDevelop(String storeCode, int offset) {
        Map<String, Object> paramMap = Maps.newHashMap();
        LocalDate localDate = new LocalDate().plusDays(offset);
        paramMap.put("statsDate", localDate.toString("yyyyMMdd"));
        paramMap.put("storeCode", storeCode);
        return dalClient.queryForObject("BIDevelopStatsService.queryStoreDevelop_DAY", paramMap,
                BiStoreDevelopDayEntity.class);
    }

    @Override
    protected List<? extends BiStaffDevelop> queryCateDevelop(String storeCode, String cateCode, int offset) {
        Map<String, Object> paramMap = Maps.newHashMap();
        LocalDate localDate = new LocalDate().plusDays(offset);
        paramMap.put("statsDate", localDate.toString("yyyyMMdd"));
        paramMap.put("storeCode", storeCode);
        if (null != cateCode) {
            paramMap.put("cateCode", cateCode);
        }
        return dalClient.queryForList("BIDevelopStatsService.queryStoreCateDevelop_DAY", paramMap,
                BiStaffDevelopDayEntity.class);
    }

    @Override
    protected BiDevelopInfo queryStaffDevelop(String storeCode, String staffId, int offset,
            Callback<SimpleRange<String>> range) {
        Map<String, Object> paramMap = Maps.newHashMap();
        LocalDate localDate = new LocalDate().plusDays(offset);
        paramMap.put("statsDate", localDate.toString("yyyyMMdd"));
        paramMap.put("storeCode", storeCode);
        paramMap.put("staffId", staffId);
        BiStaffDevelopDayEntity entity = dalClient.queryForObject("BIDevelopStatsService.queryStaffDevelop_DAY",
                paramMap, BiStaffDevelopDayEntity.class);
        range.withValue(SimpleRanges.day(localDate, "yyyyMMdd"));
        return entity;
    }

}
